﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Tools;
using Microsoft.Office.Interop.Word;
using System.Windows.Forms;

namespace docent.Addin
{
    public class UIManager
    {
        public static UIManager Instance { get; private set; }
        static UIManager() { Instance = new UIManager(); }

        private List<CustomTaskPane> _panes = new List<CustomTaskPane>();

        public void Load() 
        {
            DocPane(); 
        }
        public void GCPanes()
        {
            for (int i = _panes.Count - 1; i >= 0; i--)
            {
                if (_panes[i].Window == null)
                {
                    _panes.RemoveAt(i);
                }
            }
        }
        public CustomTaskPane DocPane()
        {
            Window window = Globals.ThisAddIn.Application.ActiveWindow;
            CustomTaskPane pane = Globals.ThisAddIn.CustomTaskPanes.SingleOrDefault(p => p.Title == "文档工作区" && p.Window == window);
            if (pane == null)
            {
                pane = CreatePane(new DocPane(), "文档工作区");
                pane.DockPosition = Microsoft.Office.Core.MsoCTPDockPosition.msoCTPDockPositionLeft;
                pane.Visible = true;
                pane.Width = 377;
            }
            return pane;
        }
        private CustomTaskPane CreatePane(UserControl control, string title)
        {
            CustomTaskPane pane = Globals.ThisAddIn.CustomTaskPanes.Add(control, title);
            _panes.Add(pane);
            return pane;
        }

        public void SyncState()
        {
            CustomTaskPane pane = UIManager.Instance.DocPane();
            //pane.Visible = UIManager.Instance.Ribbon.tgbMyBlogs.Checked;
        }
        public Ribbon Ribbon
        {
            get
            {
                Ribbon ribbon = Globals.Ribbons.SingleOrDefault(p => p.Name == "WorkspaceRibbon") as Ribbon;
                return ribbon;
            }
        }
    }
}
